package com.ruoyi.workflow.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.utils.PageRequest;
import com.ruoyi.utils.PageResult;
import com.ruoyi.utils.PaginationHelper;
import com.ruoyi.workflow.domain.Message;
import com.ruoyi.workflow.dto.CompanyApplyResDto;
import com.ruoyi.workflow.dto.MessageListHandleDto;
import com.ruoyi.workflow.dto.MessageResDto;
import com.ruoyi.workflow.service.UserMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author zhouzhixiong
 * @Date 2024/3/11 22:09
 */
@Api(tags = "用户消息相关")
@RestController
@RequestMapping("/message")
public class UserMessageController extends BaseController {

    @Resource
    private UserMessageService userMessageService;

    @ApiOperation("查询当前登录用户未办理的消息列表")
    @GetMapping("/list")
    public AjaxResult<PageResult<MessageResDto>> list(PageRequest request) {
        Long userId = SecurityUtils.getLoginUser().getUserId();
        List<MessageResDto> list = userMessageService.list(userId);
        PageRequest pageRequest = new PageRequest(request.getPageNum(), request.getPageSize());
        PageResult<MessageResDto> pageResult = PaginationHelper.paginateList(list, pageRequest);
        return AjaxResult.success(pageResult);
    }

    @ApiOperation("将消息状态从未读变为已读消息")
    @PutMapping("/handle")
    public AjaxResult<String> handle(@RequestBody MessageListHandleDto messageListHandleDto) {
        return userMessageService.handle(messageListHandleDto.getMessageIdList());
    }
    @ApiOperation("查看消息详情")
    @GetMapping("/detail")
    public AjaxResult<MessageResDto> detail(String messageId){
        return userMessageService.detail(messageId);
    }

    @ApiOperation("删除消息")
    @DeleteMapping("/delete")
    public AjaxResult<String> delete(@RequestBody MessageListHandleDto messageListHandleDto) {
        return userMessageService.delete(messageListHandleDto.getMessageIdList());
    }
}
